Skip to content

Address PR feedback from #2579 - #2611

Merged
eerhardt merged 1 commit into
dotnet:masterfrom
eerhardt:FollowUp2579
Feb 20, 2019
Merged

Address PR feedback from #2579#2611
eerhardt merged 1 commit into
dotnet:masterfrom
eerhardt:FollowUp2579

Conversation

@eerhardt

Copy link
Copy Markdown
Member

We don't need a TryConvert method, we already have a TryParse, which can be used instead.

We don't need a TryConvert method, we already have a TryParse, which can be used instead.
int csrc = 0;
if (!Conversions.Instance.TryConvert(in spanT, ref csrc) || csrc <= 0)
int csrc;
if (!Conversions.Instance.TryParse(in spanT, out csrc) || csrc <= 0)

@stephentoub stephentoub Feb 19, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that TryParse is going to be slightly more expensive, but it's unlikely to be measurable, especially given everything else going on here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly more expensive

Because of the extra write to the out parameter? Or because of the under/overflow check? Or something else?

@stephentoub stephentoub Feb 19, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra indirect write in the case of success, two extra indirect writes in the case of failure, the overflow check, the cast from the nullable rather than GetValueOrDefault, larger code that's even less likely to be inlined (though it's probably already not getting inlined). In general this code is not particularly clean.

@stephentoub

Copy link
Copy Markdown
Member

This begs the question why the methods are named Convert and TryParse, rather than Convert and TryConvert, or Parse and TryParse. As long as you're cleaning things up, seems it should be consistent.

@codecov

codecov Bot commented Feb 19, 2019

Copy link
Copy Markdown

Codecov Report

Merging #2611 into master will increase coverage by <.01%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master    #2611      +/-   ##
==========================================
+ Coverage   71.53%   71.53%   +<.01%     
==========================================
  Files         800      800              
  Lines      141866   141857       -9     
  Branches    16122    16121       -1     
==========================================
- Hits       101478   101475       -3     
+ Misses      35937    35931       -6     
  Partials     4451     4451
Flag Coverage Δ
#Debug 71.53% <0%> (ø) ⬆️
#production 67.81% <0%> (ø) ⬆️
#test 85.78% <ø> (+0.01%) ⬆️

@TomFinley TomFinley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good thank you @eerhardt

@eerhardt
eerhardt merged commit eb7c121 into dotnet:master Feb 20, 2019
@eerhardt
eerhardt deleted the FollowUp2579 branch February 20, 2019 20:28
@eerhardt

Copy link
Copy Markdown
Member Author

@stephentoub - I've logged #2669 for your concerns on the existing TryParse code.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants